// import { merchant } from "@/api/modules/merchant.js"

import { auth } from "@/api/modules/auth"

/**
 * 获取用户信息
 */
export const getUserinfo = () => {

  try {
    return wx.getStorageSync('userinfo')
  } catch (e) {

  }
}
/**
 * 设置用户信息
 */
export const setUserinfo = (userinfo) => {
  try {
    userinfo = userinfo
    wx.setStorageSync('userinfo', userinfo)
  } catch (e) {

  }
}
/**
 * 清除用户信息
 */
export const clearUserinfo = () => {
  try {
    wx.removeStorageSync('userinfo')
  } catch (e) {
  }
}


/**
 * 从接口获取用户信息
 * 
 */

export const getUserDetail = () => {
  return new Promise((resolve, reject) => {
    auth.userInfo()
      .then(({ result }) => {
        resolve(result)
        setUserinfo(result)
      })
      .catch((e) => {
        reject(e)
      })
  })
}

export const getUserAuth = (auth) => {
  const auths = getUserinfo()?.buttons || []
  return auths.includes(auth)

}
